const http = require('http')

// 原生Node设置响应头的方式

// response.writeHead(statusCode[, statusMessage][, headers])
// statusCode <number>
// statusMessage <string>
// headers <Object>

// response.setHeader(name, value)
// name <string>
// value <any>

const server = http.createServer(function (req, res) {
  const body = '<h1>你好，欢迎学习node</h1>'

  res.setHeader('X-Foo', 'bar')

  res.writeHead(200, 'OK', {
    'Content-Length': Buffer.byteLength(body),
    'content-type': 'text/html;charset=utf-8',
  })

  res.write(body)

  res.end()
})

server.listen(8080, 'localhost')
